/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.tukano.odt;

/**
 *
 * @author utente4
 */
public class OdtTableRow {
    
    private final String START = "<table:table-row>";
    private final String END = "</table:table-row>";
    private final String TOKEN;

    
    public OdtTableRow(String textInRow) {
        TOKEN = textInRow;
    }
    
    public String cloneRow(String xml) {
        int tokenIndex = xml.lastIndexOf(TOKEN);
        int startIndex = 0;
        int endIndex = 0;
        StringBuilder buffer = new StringBuilder();
        for(int i = tokenIndex; i >= 0; i--) {
            buffer.insert(0, xml.charAt(i));
            if(buffer.indexOf(START) == 0) {
                startIndex = i;
                break;
            }
        }
        endIndex = xml.indexOf(END, startIndex) + END.length();
        String head = xml.substring(0, endIndex);
        String foot = xml.substring(endIndex , xml.length());
        String row = xml.substring(startIndex, endIndex);
        xml = head + row + foot;
        return xml;
    }
}
